project(crawler)
#cmake_minimum_required(VERSION 2.6)
#include_directories(/opt/local/gcc-5.2.0/include/c++/5.2.0)
include_directories(${PROJECT_SOURCE_DIR})
# windows or linux
message(status "operation system is ${CMAKE_SYSTEM}")

# WIN32 is reserved by cmake.
message(status \n${CMAKE_CXX_COMPILER})

set(MPI_COMPILER mpicxx)
# for intel mpi
# set(MPI_COMPILER mpiicpc)

set(CMAKE_CXX_STANDARD 14)

if(WIN32)
  if(MSVC)
    message("##### MSVC #####")
    if(CMAKE_CL_64)    #CMAKE的内建变量，如果是true，就说明编译器的64位的，自然可以编译64bit的程序
      message("##### ARCH_X64 is activated #####")
      set(ADDRESS_MODEL 64)
      set(NODE_TARGET x64)
      set(ARCH_X64 "x64")
      set(X86_OR_X64 x64)
    else()
      message("##### ARCH_X86 is activated #####")
      set(ADDRESS_MODEL 32)
      set(NODE_TARGET x86)
      set(ARCH_X86 "x86")
      set(X86_OR_X64 x86)
    endif()
  elseif(MINGW)
    message("##### MINGW #####")
    message("##### ARCH_X64 is activated #####")
    set(CMAKE_CXX_FLAGS "-std=c++14 -O3")
    set(CMAKE_EXE_LINKER_FLAGS "-O3")
      set(ADDRESS_MODEL 64)
    set(NODE_TARGET x64)
    set(ARCH_X64 "x64")
    set(X86_OR_X64 x64)  
  else()
    message("##### OTHERS #####")
    message("##### ARCH_X64 is activated #####")
    set(CMAKE_CXX_FLAGS "-std=c++14 -O3")
    set(CMAKE_EXE_LINKER_FLAGS "-O3")
    set(ADDRESS_MODEL 64)
    set(NODE_TARGET x64)
    set(ARCH_X64 "x64")
    set(X86_OR_X64 x64)  
  endif(MSVC)
endif(WIN32)

if(CMAKE_SYSTEM_NAME MATCHES "Windows")
  #set(WIN32)
elseif(CMAKE_SYSTEM_NAME MATCHES "Linux")
  set(LINUX "m64")
else()
  MESSAGE(STATUS "other platform: ${CMAKE_SYSTEM_NAME}, undefined.")
endif(CMAKE_SYSTEM_NAME MATCHES "Windows")

#set(CMAKE_CXX_COMPILER "icc")
#set(CMAKE_CXX_COMPILER "icpc")
if(WIN32)
  if(ARCH_X64)
    set(EXECUTABLE_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/x64)
    set(LIBRARY_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/x64)
    link_directories(${PROJECT_SOURCE_DIR}/x64)
    #link_directories(/x64)
  else()
    set(EXECUTABLE_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/x86)
    set(LIBRARY_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/x86)
    link_directories(${PROJECT_SOURCE_DIR}/x86)
    #link_directories(/x64)
  endif()
elseif(LINUX)
  set(CMAKE_CXX_COMPILER "g++")
  set(CMAKE_CXX_FLAGS "-std=c++14 -O3 -DNDEBUG")
  set(CMAKE_EXE_LINKER_FLAGS "-ldl -O3 -DNDEBUG")

  set(EXECUTABLE_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/bin)
  set(LIBRARY_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/lib)
  link_directories(${PROJECT_SOURCE_DIR}/lib)
  #set(CMAKE_CXX_FLAGS "-std=c++11 -xHost -Wmaybe-uninitialized ")
  #set(CMAKE_EXE_LINKER_FLAGS "-ldl -xHost")
  #set(CMAKE_CXX_FLAGS "-std=c++11 -O3 -Wmaybe-uninitialized -Werror=maybe-uninitialized -Wunused-variable")
  #set(CMAKE_VERBOSE_MAKEFILE ON)
  set(CMAKE_EXPORT_COMPILE_COMMANDS 1)
  set(CMAKE_BUILD_TYPE Release)
else()
  set(CMAKE_MAKE_PROGRAM $ENV{MINGW64}/mingw32-make)
  set(CMAKE_CXX_COMPILER "g++")
  set(CMAKE_CXX_FLAGS "-std=c++14 -O3 -DNDEBUG")
  set(CMAKE_EXE_LINKER_FLAGS "-ldl -O3 -DNDEBUG")

  set(EXECUTABLE_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/bin)
  set(LIBRARY_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/lib)
  link_directories(${PROJECT_SOURCE_DIR}/lib)
  set(CMAKE_EXPORT_COMPILE_COMMANDS 1)
  set(CMAKE_BUILD_TYPE Release)
endif()

add_subdirectory(Src)
add_subdirectory(Demo)
